//学习bundle文件压缩库

#include <iostream>
#include <string>
#include <fstream>


#include "bundle.h"


int main(int argc,char* argv[])
{
    if(argc != 3)
    {
        std::cout << "compress [原始文件路径名称] [压缩包名称]" << std::endl;
        return -1;
    }

    std::string ifilename = argv[1];
    std::string ofilename = argv[2];


    std::ifstream ifs;
    ifs.open(ifilename,std::ios::binary);

    //将文件指针移动到末尾
    ifs.seekg(0,std::ios::end);
    int fsize = ifs.tellg();
    ifs.seekg(0,std::ios::beg);

    //读到body里
    std::string body;
    body.resize(fsize);

    ifs.read(&body[0],fsize);
    
    //压缩
    std::string packed = bundle::pack(bundle::LZIP,body);


    //将压缩的文件写入指定文件
    std::ofstream ofs;
    ofs.open(ofilename,std::ios::binary);
    ofs.write(&packed[0],packed.size());

    //关闭文件
    ifs.close();
    ofs.close(); 


    return 0;
}